USE SAS
GO

IF EXISTS (SELECT 1 from sysobjects where xtype = 'FN' AND NAME = 'GetAccountTypesXml')
	DROP FUNCTION dbo.GetAccountTypesXml
GO


CREATE FUNCTION dbo.GetAccountTypesXml ()
RETURNS VARCHAR(MAX)
AS
BEGIN
	
	declare 
		@result			varchar(max)

	SET @result		= '<ACCOUNTTYPES><entry id="0"></entry>'

	select @result = @result + '<entry id="' + CAST(AccountGroup AS VARCHAR) + '"><![CDATA[' +  GroupDesc + ']]></entry>'
	FROM TR_ACCTGROUP Order by GroupDesc
	SET @result = @result + '</ACCOUNTTYPES>'

	return @result

END